/*
 * Download.java
 * 
 * Created on 28.6.2007, 17:00:12
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package VidimAnetky;

/**
 *
 * @author Kuba
 */
public class Download implements Runnable {
    
    private String url, application;
    private AnetkyMidlet midlet;
    private boolean downloadSuccess = false;

    public Download(String url, String application, AnetkyMidlet midlet) {
        this.url = url;
        this.application = application;
        this.midlet = midlet;
    }
    
    public void start(){
        Thread thread = new Thread(this);
        try{
            thread.start();
        }
        catch (Exception e) {}
    }
    
    public void run(){
        try{
            getAndCallPreseneter();
        }
        catch (Exception e){
            System.err.println(e.toString());
        }
    }
    
    private void getAndCallPreseneter() throws Exception {
        String data = null;
        try{
            data = Internet.httpGet(url);
        }
        catch (Exception e) {}
        finally{
            if(data != null) {
                midlet.downloaded = data;
                midlet.bytecounter += data.length() + midlet.HTTP_HEADER_SIZE;
                midlet.showList(true, application);
            }
            else midlet.showList(false, application);
        }
    }

}
